package beans;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import dto.CandidateDTO;
import dto.PartyDTO;
import entitymanagers.CandidateManager;
import entitymanagers.CitizenManager;
import entitymanagers.PartyManager;

@ManagedBean(name = "candidateBean")
@RequestScoped
public class CandidateBean {
	@EJB
	private CandidateManager candidate;
	@EJB
	private PartyManager party;
	@EJB
	private CitizenManager citizen;
	
	private CandidateDTO candidateDTO;
	private PartyDTO partyDTO;
	
	@ManagedProperty("#{param.candidateID}")
	private String candidateID;
	

	private CandidateDTO[] allCandidates;
	
	
	public CandidateDTO getCandidate(){
		if (candidateDTO == null){
			candidateDTO = candidate.getCandidateByID();
		}
		return candidateDTO;
		
	}
	
	public CandidateDTO getNewCandidate(){
		if (candidateDTO == null){
			candidateDTO = new CandidateDTO();
		}
		return candidateDTO;
	}
	
	public PartyDTO getPartyDTO(){
		if (partyDTO == null){
			partyDTO = new PartyDTO();
		}
		return partyDTO;
	}
	public String getCandidateID(){
		return candidateID;
	}
	
	public void setCandidateID(String candidateID){
		this.candidateID = candidateID;
	}
	
	public CandidateDTO[] getAll(){
		if (allCandidates == null){
			allCandidates = candidate.getCandidates();
		}
		return allCandidates;
	}

}
